var mongoose = require("mongoose")
var movieSchema = new mongoose.Schema({
	name: String,
	year: Number,
	director:String,
	content: String,
	createTime:{
		createAt:{
			type:Data,
			default:Date.now()
		},
		updateAt{
			type:Date,
			default:Date.now()
		}
	}
	
})
movieSchema.pre("save",function(next){
	if(this.isNew){
		this.createTime.createAt = this.createTime.updateAt
	}else{
		this.createTime.update = Date.now()
	}
	next()//未知方法······
})
movieSchema.statics = {
	fetch : function(cb){
		return this.find({}).sort("createTime.updateAt")
	},
	findById:function(id,cb){
		return this
			.findOne({_id :id})
			exec(cb)
	}
}
module.exports = movieSchema